package eu.liquify.ui {
	import flash.display.DisplayObject;
	import flash.display.Shape;
	public class LabeledItem extends UIItem {
		public var FIXED_LABEL_SIZE:String = "label";
		public var FIXED_VALUE_SIZE:String = "value";
		public var PROPORTIONAL_SIZE:String = "proportional";
		
		public var labelWidth:Number = 60;
		public var itemWidth:Number = 60;
		public var spacing:Number = 3;
		
		private var _item:DisplayObject;
		
		public var layoutType:String = FIXED_VALUE_SIZE;
		
		public var reposition:Boolean = true;
		
		protected var labelTxt:Label = new Label();
		
		public function LabeledItem(options:Object = null) {
			super(options);
			if (!_item) item = null;
			
			labelTxt.padding = 0;
			labelTxt.fixedSize = true;
			labelTxt.centerY = true;
			//labelTxt.debugSize = true;
			
			labelTxt.label = label;
			addChild(labelTxt);
		}
		
		override public function set label(value:String):void {
			super.label = value;
			labelTxt.label = label;
		}
		
		public function get item():DisplayObject {
			return _item;
		}
		
		public function set item(value:DisplayObject):void {
			if (value == null) value = new Shape();
			_item = value;
		}
		
		override public function resize():void {
			super.resize();
			switch (layoutType) {
				case FIXED_LABEL_SIZE:
					labelTxt.fixedSize = true;
					labelTxt.width = labelWidth;
					if (fixedSize) {
						item.width = Math.max(0, width-labelWidth-spacing);
					} else {
						item.width = itemWidth;
					}
					break;
				case FIXED_VALUE_SIZE:
					item.width = itemWidth;
					if (fixedSize) {
						labelTxt.fixedSize = true;
						labelTxt.width = Math.max(0, width-spacing-itemWidth);
					} else {
						labelTxt.fixedSize = false;
					}
					break;
				case PROPORTIONAL_SIZE:
					if (fixedSize) {
						labelTxt.fixedSize = true;
						labelTxt.width = width/2;
						item.width = Math.max(0, width/2-spacing);
					} else {
						labelTxt.fixedSize = false;
					}
					break;
			}
			
			labelTxt.height = height;
			labelTxt.resize();
			
			var px:Number = Math.round(labelTxt.width+spacing);
			if (reposition) {
				item.x = px;
				item.y = fixedSize ? Math.round(height/2-item.height/2) : 0;
			}
			if (!fixedSize) {
				width = px+item.width;
				height = item.height;
			}
			
			/*
			txt.scrollH = 0;
			txt.autoSize = TextFieldAutoSize.NONE;
			switch (layoutType) {
				case FIXED_LABEL_SIZE:
					labelTxt.fixedSize = true;
					labelTxt.width = labelWidth;
					if (fixedSize) {
						txt.width = Math.max(0, width-labelWidth-spacing);
					} else {
						txt.width = valueWidth;
					}
					break;
				case FIXED_VALUE_SIZE:
					txt.width = valueWidth;
					if (fixedSize) {
						labelTxt.fixedSize = true;
						labelTxt.width = Math.max(0, width-spacing-valueWidth);
					} else {
						labelTxt.fixedSize = false;
					}
					break;
				case PROPORTIONAL_SIZE:
					if (fixedSize) {
						labelTxt.fixedSize = true;
						labelTxt.width = width/2;
						txt.width = Math.max(0, width/2-spacing);
					} else {
						labelTxt.fixedSize = false;
						txt.autoSize = TextFieldAutoSize.LEFT;
					}
					break;
			}
			
			labelTxt.resize();
			txt.x = labelTxt.width+spacing;
			
			if (fixedSize) {
				content.y = height/2-content.height/2-1;
			} else {
				content.y = 0;
				width = txt.x+txt.width;
				height = content.height;
			}*/
		}
		
	}

}